package cn.auction.dao.impl;

import cn.auction.dao.AuctionUserDao;
import cn.auction.entity.AuctionUser;
import my.framework.dao.CommonDao;
import java.util.List;

public class AuctionUserDaoImpl implements AuctionUserDao {
    private CommonDao dao = new CommonDao();

    public AuctionUserDaoImpl() {
    }

    public AuctionUser selectUser(String userName, String userPassword, boolean isAdmin) throws Exception {
        String sql = "select * from auctionUser a where userName=? and userPassword=? and userIsAdmin = ?";
        List<AuctionUser> list = this.dao.executeQuery(AuctionUser.class, sql, new Object[]{userName, userPassword, isAdmin});
        return list != null && list.size() != 0 ? (AuctionUser)list.get(0) : null;
    }

    public void insert(AuctionUser user) throws Exception {
        String sql = "insert into auctionUser(userName, userPassword, userCardNo, userTel, userAddress, userPostNumber, userIsAdmin, userQuestion, userAnswer) values(#{userName}, #{userPassword}, #{userCardNo}, #{userTel}, #{userAddress}, #{userPostNumber}, #{userIsAdmin}, #{userQuestion}, #{userAnswer})";
        this.dao.executeUpdate(sql, user);
    }

    public AuctionUser findById(Long userId) throws Exception {
        String sql = "select * from auctionUser where userId = ?";
        List<AuctionUser> list = this.dao.executeQuery(AuctionUser.class, sql, new Object[]{userId});
        return list != null && list.size() != 0 ? (AuctionUser)list.get(0) : null;
    }
}
